<?php 
class Peminjaman_model extends CI_Model{

		function __construct(){
			parent::__construct();
		
		
		}
		
		function getPeminjaman($query=FALSE,$id=FALSE,$limit=FALSE,$offset=FALSE){
				if ($query == 'list'){
					$this->db->limit($limit,$offset);
					$this->db->join('tb_member', 'tb_member.id_member=tb_peminjaman.id_member');
					//$this->db->where('tb_peminjaman.status','1');
					$this->db->order_by('tgl_pinjam','desc');
					
					return $this->db->get('tb_peminjaman')->result_array();
				
				}
				
				elseif ($query == 'by_id'){
					$this->db->join('tb_member', 'tb_member.id_member=tb_peminjaman.id_member');
					$this->db->where('id_peminjaman',$id);
					return $this->db->get('tb_peminjaman')->row();
				
				
				}
				elseif ($query == 'by_id_member'){
					$this->db->join('tb_member', 'tb_member.id_member=tb_peminjaman.id_member');
					$this->db->join('tb_detail_peminjaman','tb_detail_peminjaman.id_peminjaman = tb_peminjaman.id_peminjaman');
					$this->db->join('tb_buku','tb_buku.id_buku = tb_detail_peminjaman.id_buku');
					$this->db->join('tb_penerbit','tb_penerbit.id_penerbit = tb_buku.id_penerbit');
					$this->db->where('tb_detail_peminjaman.id_detail',$id);
					return $this->db->get('tb_peminjaman')->row();
				}
				
				elseif ($query == 'by_judul'){
					$this->db->join('tb_member', 'tb_member.id_member=tb_peminjaman.id_member');
					$this->db->join('tb_detail_peminjaman','tb_detail_peminjaman.id_peminjaman = tb_peminjaman.id_peminjaman');
					$this->db->join('tb_buku','tb_buku.id_buku = tb_detail_peminjaman.id_buku');
					$this->db->join('tb_penerbit','tb_penerbit.id_penerbit = tb_buku.id_penerbit');
					$this->db->where('tb_peminjaman.id_peminjaman',$id);
					return $this->db->get('tb_peminjaman')->result_array();
				}
				
				
				elseif($query == 'temp') {
					$this->db->join('tb_member','tb_member.id_member=tb_ses.id_member');
					$this->db->join('tb_buku','tb_buku.id_buku=tb_ses.id_buku');
					$this->db->where('tb_ses.id_member',$id);
						return $this->db->get('tb_ses')->result_array();
				
				
				}
				
		
		
		}
		
		function addDetail($data){
			$this->db->insert('tb_detail_peminjaman',$data);
					
		}
		function editDetail($id_detail,$data){
			$this->db->where('id_detail',$id_detail);
			$this->db->update('tb_detail_peminjaman',$data);
				
		}
		
		
		function addPeminjaman($data){
			$this->db->insert('tb_peminjaman',$data);
					
		}
		
		function editPeminjaman($id,$data){
			$this->db->where('id_peminjaman',$id);
			$this->db->update('tb_peminjaman',$data);
				
		}
		
		
		
		function deletePeminjaman($id){
			$this->db->where('id_detail',$id);
			$this->db->delete('tb_detail_peminjaman');
		
		}
		
		
		
		
		function addRekap($data){
			$this->db->insert('tb_rekap_peminjaman',$data);
					
		}
		
		function editPinjam($id_pinjam,$data1){
			$this->db->where('id_pinjam',$id_pinjam);
			$this->db->update('tb_rekap_peminjaman',$data1);
				
		}
		
		function deletePinjam($id){
			$this->db->where('id_pinjam',$id);
			$this->db->delete('tb_rekap_peminjaman');
		
		}
		
		function addTempPinjam($data){
			$this->db->insert('tb_ses',$data);
					
		}

}


?>